package cn.Mmovie.servlet;

import cn.Mmovie.bean.Auditorium;
import cn.Mmovie.bean.Cinema;
import cn.Mmovie.service.AuditoriumService;
import cn.Mmovie.service.CinemaService;
import cn.Mmovie.service.impl.AuditoriumServiceImpl;
import cn.Mmovie.service.impl.CinemaServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "AdminAuditoriumModifyServlet", value = "/admin/auditorium_modify")
public class AdminAuditoriumModifyServlet extends HttpServlet {
    private CinemaService cinemaService=new CinemaServiceImpl();
    private AuditoriumService auditoriumService=new AuditoriumServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("---------AuditoriumModify--------");
        if (request.getParameter("id")==null||request.getParameter("id")==""){
            request.setAttribute("failMsg","没有指定需要修改的放映厅，请重试！");
            request.getRequestDispatcher("/admin/auditorium_list").forward(request,response);
        }
        Integer id=Integer.parseInt(request.getParameter("id"));
        System.out.println(id);
        List<Cinema> cinemas=cinemaService.queryAllCinema();
        Auditorium auditorium=auditoriumService.queryById(id);
        if (auditorium!=null){
            request.setAttribute("cinemas",cinemas);
            request.setAttribute("auditorium",auditorium);
            request.getRequestDispatcher("/WEB-INF/page/main/auditorium_modify.jsp").forward(request,response);
        }else {
            request.setAttribute("failMsg","需要修改的电影院不存在，请重试！");
            request.getRequestDispatcher("/admin/auditorium_list").forward(request,response);
        }
    }
}
